import {post} from '../../common/http/http.service';

type pageType = {
  pageNo?: number;
  pageSize?: number;
};

type paramsType = {
  dataSource?: 0 | 1; // 0：管理员 1：小程序 不传默认全部
  name?: string; // 故事名称
  types?: number[]; // 故事类型id 例：[100009]
  sort?: [
    {
      // 首页故事类型
      key: string;
      value: string;
    },
  ];
  id?: number; // 故事id
} & pageType;

type saveStoryType = {
  protagonist: string[];
  minorRole: string[];
  abilityNames: string;
  paintStyleName: string;
  wordage: string;
  description: string;
  share: boolean;
};

export interface StoryItemType {
  abilityIds: null | number;
  abilityNames: null | string;
  ageIds: null | number;
  ageNames: null | string;
  book: boolean;
  collectNum: number;
  compose: number;
  cover: null | string;
  createAvatar: null | string;
  createId: string;
  createName: string;
  createTime: string;
  dataSource: string;
  deleted: boolean;
  description: null | string;
  episodeList: Array<{
    content: null | string;
    createTime: string;
    description: null | string;
    file: string;
    icon: null | string;
    id: null | number;
    name: null | string;
    num: number;
    storyId: number;
  }>;
  episodes: Array<number>;
  forwardNum: number;
  icon: null | string;
  id: number;
  name: string;
  paintStyleId: null | number;
  praiseNum: number;
  readNum: number;
  sameStyleNum: number;
  share: boolean;
  title: string;
  typeId: Array<number>;
  typeNames: Array<string>;
  unit: boolean;
  wordage: number;
}

/*
 * @Description: 登陆模块请求
 * @Author: liuzhen
 */
export class StoryService {
  // 新查询故事
  newPage(params: paramsType): Promise<any> {
    return post('/story/api/story/page', params);
  }

  // 故事页故事查询
  storyPage(params: paramsType): Promise<any> {
    return post('/story/api/story/info', params);
  }

  // 新故事页故事查询
  storyCache(params: paramsType): Promise<any> {
    return post('/story/api/story/storyCache', params);
  }

  // 组装故事
  assemblyData(params: saveStoryType): Promise<any> {
    return post('/story/api/story/assemblyData', params);
  }

  // 查询故事类别
  getStoryCategory(
    params: {advertisementName?: string} & pageType,
  ): Promise<any> {
    return post('/story/api/storyCategory/page', params);
  }

  // 查询故事类别数据
  getCategoryData(params: {categoryId: number} & pageType): Promise<any> {
    return post('/story/api/categoryData/pagee', params);
  }

  // 查询故事详情
  getStoryDetail(params: {id: number}): Promise<any> {
    return post('/story/api/story/page', params);
  }

  // 查询故事收藏点赞等信息
  findDetails(params: {storyId: number}): Promise<any> {
    return post('/story/api/story/findDetails', params);
  }

  // 查询浏览记录
  getReadRecord(params: pageType): Promise<any> {
    return post('/story/api/storyRecord/page', params);
  }

  // 添加浏览记录
  addReadRecord(params: {storyId: number}): Promise<any> {
    return post('/story/api/storyRecord/save', params);
  }

  // 查询收藏记录
  getCollectRecord(params: {storyName?: string} & pageType): Promise<any> {
    return post('/story/api/collectRecord/page', params);
  }

  // 添加收藏记录
  addCollectRecord(params: {storyId: number}): Promise<any> {
    return post('/story/api/collectRecord/save', params);
  }

  // 取消收藏记录
  cancelCollectRecord(params: {storyId: number}): Promise<any> {
    return post('/story/api/collectRecord/remove', params);
  }

  // 查询点赞记录
  getLikeRecord(params: {storyName?: string} & pageType): Promise<any> {
    return post('/story/api/likeRecord/page', params);
  }

  // 添加点赞记录
  addLikeRecord(params: {storyId: number}): Promise<any> {
    return post('/story/api/likeRecord/save', params);
  }

  // 取消点赞记录
  cancelLikeRecord(params: {storyId: number}): Promise<any> {
    return post('/story/api/likeRecord/remove', params);
  }

  // 查询转发记录
  getForwardingRecord(params: pageType): Promise<any> {
    return post('/story/api/forwardingRecord/page', params);
  }

  // 添加转发记录
  addForwardingRecord(params: {storyId: number}): Promise<any> {
    return post('/story/api/forwardingRecord/save', params);
  }

  // 添加同款计数
  addSameStyleRecord(params: {storyId: number}): Promise<any> {
    return post('/story/api/sameStyleRecord/save', params);
  }
}
